package com.coffee.excel.builder;

import com.coffee.excel.metadata.MochaExcelField;
import com.coffee.excel.executor.ExportExcelExecutor;
import com.coffee.excel.metadata.MochaExportParameter;

import java.io.OutputStream;
import java.util.List;

/**
 * @author: songkui
 * @since: 2023/2/14 11:01
 */
public class ExportExcelBuilder<T> extends BasicExcelBuilder {

    private final MochaExportParameter exportParameter;

    public ExportExcelBuilder(List<MochaExcelField> fieldList, String title){

        setColumnIndex(fieldList);
        exportParameter = new MochaExportParameter();
        exportParameter.setFieldList(fieldList);
        exportParameter.setTitleName(title);

        exportParameter.setHead(headShow(fieldList));
        exportParameter.setHeadColorMap(headColorMap(fieldList));
        exportParameter.setTemplateList(exportTemplateData(fieldList));
        exportParameter.setMergeAddressList(mergeAddressList(fieldList));
    }

    public ExportExcelBuilder<T> outputStream (OutputStream outputStream){
        exportParameter.setOutputStream(outputStream);
        return this;
    }

    /**
     * T: 既可以是 对象； 也可以是map 形式； 只要字段能对应 即可；
     * 所以， 导出 最好是 重新封装一个对象； 因为不能引用；eg. 对象里面套对象
     * @param data List<T>
     */
    public void doExport(List<T> data){
        ExportExcelExecutor<T> exportExcelExecutor = new ExportExcelExecutor<>(exportParameter);
        exportExcelExecutor.doExport(data);
    }


}
